﻿<UserControl x:Class="FacebookClient.PhotoUploadWizard"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:FacebookClient="clr-namespace:FacebookClient"
    xmlns:Facebook="clr-namespace:Contigo;assembly=Contigo"
    xmlns:ClientManagerControls="clr-namespace:ClientManager.Controls" 
    x:Name="ThisControl">
  <UserControl.Template>
    <ControlTemplate TargetType="{x:Type FacebookClient:PhotoUploadWizard}">
      <Border MinWidth="400" Background="{DynamicResource ApplicationBarBackground}" BorderBrush="{DynamicResource ApplicationBarBorderBrush}" BorderThickness="4">
        <Grid>
          
          <Grid x:Name="PART_PickAlbumPage" Visibility="Collapsed">
            <Grid.RowDefinitions>
              <RowDefinition Height="Auto"/>
              <RowDefinition Height="*"/>
              <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <TextBlock Grid.Row="0"
              Margin="8"
              HorizontalAlignment="Center"
              FontSize="{DynamicResource LargeFontSize3}" 
              FontFamily="{DynamicResource SansSerifFont}" 
              Foreground="White" 
              Text="Upload photos" />

            <ScrollViewer Background="{DynamicResource MainContentBackgroundBrush}" Grid.Row="1" Style="{DynamicResource MainScrollViewerStyle}" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">

              <FacebookClient:AnimatingTilePanel ItemHeight="280" ItemWidth="350" Attraction="2.4" MaxWidth="800" >
                <StackPanel Orientation="Vertical" Width="350" Height="280">
                  <TextBox HorizontalAlignment="Center" Text="{Binding ElementName=PART_ZapScroller, Path=CurrentItem.Description, UpdateSourceTrigger=PropertyChanged}" 
                             ToolTip="Photo Caption" Margin="0,10,0,0" Style="{DynamicResource CaptionTextBoxStyle}" Width="330" MinHeight="20" TextWrapping="Wrap"
                             AcceptsReturn="True" />

                  <FacebookClient:ZapScroller Grid.Row="3" HorizontalAlignment="Center" x:Name="PART_ZapScroller" Height="180" ClipToBounds="True" 
                                                     ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Files}" Margin="0,10,0,0">
                    <FacebookClient:ZapScroller.ItemTemplate>
                      <DataTemplate>
                        <StackPanel HorizontalAlignment="Center" Orientation="Horizontal" >
                          <Viewbox MaxHeight="180" MaxWidth="240"  HorizontalAlignment="Center" VerticalAlignment="Top">
                            <Image Stretch="UniformToFill" Source="{Binding Path}"/>
                          </Viewbox>
                          <Button HorizontalAlignment="Right" Cursor="Hand" Margin="-16,0,0,0" VerticalAlignment="Top" Width="20" Height="20" Style="{DynamicResource RemoveItemButtonStyle}" Click="RemovePhotoButtonClick"  ToolTip="Remove this photo" Content="X" />
                        </StackPanel>
                      </DataTemplate>
                    </FacebookClient:ZapScroller.ItemTemplate>
                  </FacebookClient:ZapScroller>

                  <Grid Margin="0,10,0,0" HorizontalAlignment="Center">
                    <Grid.ColumnDefinitions>
                      <ColumnDefinition Width="Auto" />
                      <ColumnDefinition Width="Auto" />
                      <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <RepeatButton 
                        Command="{Binding ElementName=PART_ZapScroller, Path=PreviousCommand}"
                        Style="{DynamicResource SimpleButtonBaseStyle}"
                        Width="28"
                        Height="20"
                        Margin="5,0"
                        VerticalAlignment="Center">
                      <Rectangle Fill="{DynamicResource LeftArrowToolbarDrawingBrush}"/>
                    </RepeatButton>
                    
                    <TextBlock Grid.Column="1" Style="{DynamicResource ToolbarTextBlockStyle}" TextAlignment="Center" MinWidth="80">
                      <TextBlock.Text>
                        <MultiBinding StringFormat="{}{0} of {1}">
                          <Binding ElementName="PART_ZapScroller" Path="CurrentItemIndex" Converter="{StaticResource AddConverter}" ConverterParameter="1"/>
                          <Binding ElementName="PART_ZapScroller" Path="ItemCount"/>
                        </MultiBinding>
                      </TextBlock.Text>
                    </TextBlock>

                    <RepeatButton Grid.Column="2"
                        Command="{Binding ElementName=PART_ZapScroller, Path=NextCommand}"
                        Style="{DynamicResource SimpleButtonBaseStyle}"
                        Width="28"
                        Height="20"
                        Margin="5,0"
                        VerticalAlignment="Center">
                      <Rectangle Fill="{DynamicResource RightArrowToolbarDrawingBrush}"/>
                    </RepeatButton>
                  </Grid>
                </StackPanel>

                <StackPanel HorizontalAlignment="Center" Margin="0,5,0,0">

                  <TextBlock
                      Margin="5" 
                      Text="Choose album:" 
                      HorizontalAlignment="Left"
                      Style="{DynamicResource ToolbarTextBlockStyle}" />

                  <ComboBox x:Name="PART_AlbumsComboBox"
                            Width="250" 
                            MinHeight="40" 
                            Style="{DynamicResource MyComboBoxStyle}" 
                            Margin="5"
                            HorizontalAlignment="Left">
                    <ComboBox.Resources>
                      <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FFCEDEE8"/>
                      <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" />
                    </ComboBox.Resources>
                    <ComboBox.ItemTemplate>
                      <DataTemplate>
                        <StackPanel HorizontalAlignment="Left" Orientation="Horizontal" Height="34">
                          <ClientManagerControls:FacebookImageControl FacebookImage="{Binding Path=CoverPic.Image}" FacebookImageDimensions="Small" ToolTip="{Binding Path=Description}" >
                            <ClientManagerControls:FacebookImageControl.Template>
                              <ControlTemplate TargetType="{x:Type ClientManagerControls:FacebookImageControl}">
                                <Image Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ImageSource}" Stretch="UniformToFill" />
                              </ControlTemplate>
                            </ClientManagerControls:FacebookImageControl.Template>
                          </ClientManagerControls:FacebookImageControl>
                          <TextBlock TextTrimming="CharacterEllipsis" 
                                 Text="{Binding Title}" 
                                 Foreground="White"
                                 FontFamily="{DynamicResource SansSerifFont}"
                                 FontSize="{DynamicResource MiddleFontSize}"
                                 HorizontalAlignment="Center" 
                                 VerticalAlignment="Center" 
                                 Margin="5"/>
                        </StackPanel>
                      </DataTemplate>
                    </ComboBox.ItemTemplate>
                  </ComboBox>

                  <TextBlock 
                      Margin="5"
                      HorizontalAlignment="Left"
                      Style="{DynamicResource ToolbarTextBlockStyle}"
                      Text="Album title:"/>

                  <TextBox Margin="5"
                           x:Name="PART_AlbumName" 
                           Text="{Binding ElementName=PART_AlbumsComboBox, Path=SelectedItem.Title, Mode=OneWay}" 
                           Style="{DynamicResource CaptionTextBoxStyle}" 
                           HorizontalAlignment="Left"
                           Width="250" Height="20" FontWeight="Normal" TextWrapping="Wrap" IsEnabled="False" Opacity=".7" />

                  <TextBlock Style="{DynamicResource ToolbarTextBlockStyle}"
                         Margin="5" 
                         HorizontalAlignment="Left"
                         Text="Album location:" />
                  <TextBox Margin="5" 
                           HorizontalAlignment="Left"
                           x:Name="PART_AlbumLocation" 
                           Text="{Binding ElementName=PART_AlbumsComboBox, Path=SelectedItem.Location, Mode=OneWay}" 
                           Style="{DynamicResource CaptionTextBoxStyle}" Width="250" Height="20" FontWeight="Normal" TextWrapping="Wrap" IsEnabled="False" Opacity=".7" />

                  <TextBlock 
                    Margin="5"
                    HorizontalAlignment="Left"
                    Style="{DynamicResource ToolbarTextBlockStyle}"
                    Text="Album description:" />
                  <TextBox Margin="5" x:Name="PART_AlbumDescription" 
                           HorizontalAlignment="Left"
                           Text="{Binding Description,  Path=SelectedItem.Description, Mode=OneWay}"  
                           Style="{DynamicResource CaptionTextBoxStyle}" Width="250" Height="20" FontWeight="Normal" TextWrapping="Wrap" IsEnabled="False" Opacity=".7" />
                </StackPanel>

              </FacebookClient:AnimatingTilePanel>
            </ScrollViewer>

            <StackPanel Grid.Row="2" Margin="0,5,10,10" Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Right">
              <Button Style="{DynamicResource StandardButtonStyle}" Content="Upload"  Margin="10,0,0,0" Command="{x:Static FacebookClient:PhotoUploadWizard.UploadCommand}"/>
              <Button Style="{DynamicResource StandardButtonStyle}" Content="Cancel"  Margin="10,0,0,0" Click="CancelButtonClick"/>
            </StackPanel>

          </Grid>

          <Grid Height="Auto" x:Name="PART_UploadPage" Visibility="Collapsed" Margin="15">                                          
            <Grid.RowDefinitions>
              <RowDefinition Height="Auto"/>
              <RowDefinition Height="170"/>
              <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <TextBlock x:Name="PART_UploadPhotoStatusTextBlock" Margin="8,16" Foreground="White" FontSize="{DynamicResource LargeFontSize3}" HorizontalAlignment="Center" FontFamily="{DynamicResource SansSerifFont}" TextAlignment="Center" MinWidth="50" TextWrapping="Wrap" />

            <Grid Grid.Row="1">
              <Border x:Name="NextPhotoToUpload" Margin="0,10" DockPanel.Dock="Bottom" BorderBrush="Gray" BorderThickness="0">
                <Image x:Name="PART_NextPhotoImage" MaxWidth="300" MaxHeight="150" Margin="0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
              </Border>
              <TextBlock Margin="0,0,0,0" x:Name="PART_UploadStatus" FontSize="{DynamicResource LargeFontSize4}" HorizontalAlignment="Center" 
                                       Foreground="White" FontFamily="{DynamicResource SansSerifFont}" DockPanel.Dock="Bottom" Opacity="0.8" Visibility="Visible"/>
            </Grid>

            <Button Grid.Row="2" VerticalAlignment="Bottom" HorizontalAlignment="Right" Style="{DynamicResource StandardButtonStyle}" Margin="10,0,0,0" Click="CancelButtonClick"
                                x:Name="PART_CloseCancelButton"/>
          </Grid>
        </Grid>
      </Border>
      
      <ControlTemplate.Triggers>
        <Trigger Property="Page" Value="PickAlbum">
          <Setter TargetName="PART_PickAlbumPage" Property="Visibility" Value="Visible"/>
        </Trigger>
        <Trigger Property="Page" Value="Upload">
          <Setter TargetName="PART_UploadPage" Property="Visibility" Value="Visible"/>
        </Trigger>
        <Trigger SourceName="PART_AlbumsComboBox" Property="SelectedIndex" Value="0" >
          <Setter TargetName="PART_AlbumName" Property="UIElement.IsEnabled" Value="True"/>
          <Setter TargetName="PART_AlbumName" Property="UIElement.Opacity" Value="1"/>
          <Setter TargetName="PART_AlbumLocation" Property="UIElement.IsEnabled" Value="True"/>
          <Setter TargetName="PART_AlbumLocation" Property="UIElement.Opacity" Value="1"/>
          <Setter TargetName="PART_AlbumDescription" Property="UIElement.IsEnabled" Value="True"/>
          <Setter TargetName="PART_AlbumDescription" Property="UIElement.Opacity" Value="1"/>
        </Trigger>
      </ControlTemplate.Triggers>
    </ControlTemplate>

  </UserControl.Template>
</UserControl>
